package com.woniu.humanresource.controller;


import com.woniu.humanresource.entity.Departure;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.entity.SalarysTructure;
import com.woniu.humanresource.exception.GeneralException;

import com.woniu.humanresource.service.SalarysTructureService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//薪酬结构
@RestController
public class SalarysTructureController {
    @Resource
    SalarysTructureService salarysTructureService;
    //分页查询企业福利
    @PostMapping("/salarystructure/{pageIndex}/{pageSize}")
    public ResponseText getSalarysTructure(
            @PathVariable("pageIndex") int pageIndex,
            @PathVariable("pageSize") int pageSize,
            @RequestBody SalarysTructure salarysTructure){
        ResponseText<PageBean<SalarysTructure>> responseText=null;
        try {

            PageBean<SalarysTructure> pageBean = salarysTructureService.selectSalarysTructure(salarysTructure, pageIndex, pageSize);
            responseText=new ResponseText<>(pageBean,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //添加企业福利
    @PostMapping("/addsalarystructure")
    public ResponseText addCorporateBenefits(@RequestBody SalarysTructure salarysTructure){
        ResponseText responseText=null;
        try {
            //待面试状态
            salarysTructureService.insertSalarysTructure(salarysTructure);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //删除企业福利
    @DeleteMapping("/salarystructure/{id}")
    public ResponseText deleteCorporateBenefits(@PathVariable("id") int id){
        ResponseText responseText=null;
        try {
            salarysTructureService.deleteSalarysTructure(id);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //修改企业福利
    @PutMapping("/updateupdatesalarystructure")
    public ResponseText updateDeparture(@RequestBody SalarysTructure salarysTructure){
        ResponseText responseText=null;
        try {
            salarysTructureService.updateSalarysTructure(salarysTructure);
            responseText=new ResponseText<PageBean<SalarysTructure>>(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

}
